using Avalonia.BiliBili.Libs.Models;
using Avalonia.BiliBili.ViewModels;
using Avalonia.Controls;
using Avalonia.Extensions.Controls;
using Avalonia.Interactivity;
using Bilibili.Model.Common;
using System.Diagnostics;

namespace Avalonia.BiliBili.Windows
{
    public partial class DynamicInfoWindow : WindowBase
    {
        private DynamicInfoViewModel ViewModel { get; }
        public DynamicInfoWindow()
        {
            InitializeComponent();
            ViewModel = new DynamicInfoViewModel(this);
        }
        protected override void AfterInitializeComponent()
        {
            DataContext = ViewModel;
        }
        public override void Callback()
        {
            RunOnUiThread(async () =>
            {
                if (Data is DynamicCardsData data)
                {
                    ViewModel.DynamicCardsData = data;
                    if (data.DynamicCards != null)
                    {
                        ViewModel.DynamicCards = data.DynamicCards;
                        ViewModel.LoadDynamicView();
                        ViewModel.LoadDynamicComment();
                    }
                    else
                    {
                        data.AlbumId = await ViewModel.GetDynamicId(data.AlbumId);
                        await ViewModel.LoadDynamicData(data.AlbumId);
                    }
                }
            });
        }
        public void AddView(Control controlContent)
        {
            content.Content = controlContent;
        }
        public void InitComment(CommentType type, string id)
        {
            comment.InitInfo(this, type, id);
            comment.InitComment();
        }
        private void OnContentClick(object? sender, RoutedEventArgs e)
        {
            RunOnUiThread(async () =>
            {
                if (sender is ImageContentButton button)
                {
                    switch (button.Tag.ToString())
                    {
                        case "like":
                            {
                                await ViewModel.Like();
                                break;
                            }
                        case "Comment":
                            {

                                break;
                            }
                        case "share":
                            {

                                break;
                            }
                        case "more":
                            {

                                break;
                            }
                    }
                }
            });
        }
    }
}